import "dotenv/config";

import db from "../src/database.js";

const MyTags = ["express", "elysia", "hono"];

(async () => {
  // 多条插入
  // const [results] =
  //   await db.query`INSERT INTO Tag (name, ownerId) values ${MyTags.map(
  //     (tag) => [tag, 1]
  //   )}`;
  // // 只返回了第一条的 id，insertId 并不是数组
  // console.log(results);
  const tags = await db.findAll`select tagId from PostTags where postId = 1`;
  console.log(tags.reduce((p, c) => p.concat(c.tagId), []));
  // in 运算符
  await db.run`DELETE FROM PostTags WHERE tagId in (${[2, 3]})`;
  // like 运算符
  await db.run`select * from Post where title like ${`%vue%`}`;
  //
  await db.close();
})();
